package vg.modules.attribute_panel.components;

import java.awt.Component;

import javax.swing.AbstractCellEditor;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;



public class AttributeTableCellEditor extends AbstractCellEditor implements TableCellEditor {
	private static final long serialVersionUID = 1000L;
	//-------------------------------------------------------------------------
	private Object lastObject;
	private AttributeTableCellRenderer renderer;
	/**
	 * Attribute editor constructor.
	 * @param model - storage of data.
	 */
	public AttributeTableCellEditor(AttributeTableModel model, AttributeTableCellRenderer renderer) {
		this.renderer = renderer;
	}
	/**
	 *  This method is called when a cell value is edited by the user.
	 */
	public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int rowIndex, int colIndex) {
		this.lastObject = table.getValueAt(rowIndex, colIndex);
		return(this.renderer.getTableCellRendererComponent(table, value, isSelected, isSelected, rowIndex, colIndex));
	}
	/**
	 * This method is called when editing is completed.
	 * It must return the new value to be stored in the cell.
	 */
	public Object getCellEditorValue() {
		return(this.lastObject);
	}
}
